<?php
/**
 * Created by PhpStorm.
 * User: xiaosq
 * Date: 2018/6/19
 * Time: 11:12
 */

namespace App\Handlers;

require_once __DIR__.'/php_sdk/include.php';
use TencentYoutuyun\Youtu;
use TencentYoutuyun\Conf;

class Face
{
    private $appId = '';
    private $secretId = '';
    private $secretKey = '';
    private $userId = '';

    /**
     * 初始化 API
     */
    public function __construct($userId = '')
    {
        $this->appId = config('face.appId');
        $this->secretId = config('face.secretId');
        $this->secretKey = config('face.secretKey');
        $this->userId = $userId;

        Conf::setAppInfo($this->appId, $this->secretId, $this->secretKey, $this->userId, conf::API_YOUTU_END_POINT );
    }

    /**
     * 个体创建
     * @param $url
     * @param $person_id
     * @param array $group_ids
     * @param string $person_name
     * @param string $person_tag
     * @return \TencentYoutuyun\返回的结果，JSON字符串，字段参见API文档
     */
    public function newPersonUrl($url, $person_id, array $group_ids, $person_name='', $person_tag='')
    {
        $ret = Youtu::newpersonurl($url, $person_id, $group_ids, $person_name, $person_tag);

        return $ret;
    }

    /**
     * 个体删除
     * @param $person_id
     * @return \TencentYoutuyun\返回的结果，JSON字符串，字段参见API文档
     */
    public function delPerson($person_id)
    {
        $ret = Youtu::delperson($person_id);

        return $ret;
    }

    /**
     * 增加人脸url
     * @param $person_id
     * @param array $url_arr
     * @param string $facetag
     * @return \TencentYoutuyun\返回的结果，JSON字符串，字段参见API文档
     */
    public function addFaceUrl($person_id, array $url_arr, $facetag='')
    {
        $ret = Youtu::addfaceurl($person_id, $url_arr, $facetag);

        return $ret;
    }

    /**
     * 删除人脸
     * @param $person_id
     * @param array $face_id_arr
     * @return \TencentYoutuyun\返回的结果，JSON字符串，字段参见API文档
     */
    public function delFace($person_id, array $face_id_arr)
    {
        $ret = Youtu::delface($person_id, $face_id_arr);

        return $ret;
    }

    /**
     * 人脸验证base64
     * @param $image_data
     * @param $person_id
     * @return mixed|string
     */
    public function faceVerifyBase($image_data,$person_id)
    {
        $ret = Youtu::faceverifybase($image_data, $person_id);

        return $ret;
    }

    /**
     * 人脸验证url
     * @param $url
     * @param $person_id
     * @return \TencentYoutuyun\返回的结果，JSON字符串，字段参见API文档
     */
    public function faceVerifyUrl($url, $person_id)
    {
        $ret = Youtu::faceverifyurl($url, $person_id);

        return $ret;
    }

    /**
     * 人脸检索base64
     * @param $image_data
     * @param $group_id
     * @param array $group_ids
     * @param int $topn
     * @param int $min_size
     * @return \TencentYoutuyun\返回的结果，JSON字符串，字段参见API文档
     */
    public function multiFaceIdentifyBase($image_data, $group_id, $group_ids = [], $topn=5, $min_size=40)
    {
        $ret = Youtu::multifaceidentifybase($image_data, $group_id, $group_ids, $topn, $min_size);

        return $ret;
    }

    /**
     * 人脸检测url
     * @param $image_url
     * @param int $isbigface
     * @return \TencentYoutuyun\返回的结果，JSON字符串，字段参见API文档
     */
    public function detectFaceUrl($image_url, $isbigface = 1)
    {
        $ret = Youtu::detectfaceurl($image_url, $isbigface);

        return $ret;
    }
}